/*
 * Copyright (c) 2005 -2008 Reliable Source, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Mozilla Public License v.1.1,
 * BSD, and Eclipse Public License v1.0 which accompanies this
 * distribution and is available at:
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 * 		http://www.opensource.org/licenses/bsd-license.php
 * 		http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * Contributors:
 *     IBM Corporation	     -  http://ibm.com
 *     	- initial API and implementation
 *
 *     patientos.org         - http://patientos.org
 *     	- domain and database persistence layer
 *
 *     Reliable Source, Inc. - http://reliablesource.org
 *     	- Symbiosys Application Framework,
 *     	- Symbiosys Application, Symbiosys Product
 *
 */
package org.reliablesource.symbiosys.ui.tests.images;

import junit.framework.TestCase;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IconAndMessageDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.window.Window;

import org.eclipse.swt.graphics.Image;


/**
 *
 * ImageRegistryTest.java<br>
 * Created on: Jun 27, 2008<br>
 *
 * @author <a href="mailto:dennis.park@gmail.com">Dennis Park</a>
 *
 * @category
 * @since 1.0
 */
public class ImageRegistryTest extends TestCase {
    public ImageRegistryTest(String name) {
        super(name);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(ImageRegistryTest.class);
    }

    public void testGetNull() {
        ImageRegistry reg = JFaceResources.getImageRegistry();

        Image result = reg.get((String) null);
        assertTrue("Registry should handle null", result == null);
    }

    public void testGetString() {
        // note, we must touch the class to ensure the static initialer runs
        // so the image registry is up to date
        Dialog.getBlockedHandler();

        String[] imageNames = new String[] {
                Dialog.DLG_IMG_ERROR, Dialog.DLG_IMG_INFO,
                Dialog.DLG_IMG_QUESTION, Dialog.DLG_IMG_WARNING,
                Dialog.DLG_IMG_MESSAGE_ERROR, Dialog.DLG_IMG_MESSAGE_INFO,
                Dialog.DLG_IMG_MESSAGE_WARNING
            };

        ImageRegistry reg = JFaceResources.getImageRegistry();

        for (int i = 0; i < imageNames.length; i++) {
            String imageName = imageNames[i];
            Image image1 = reg.get(imageName);
            assertTrue("Returned null image", image1 != null);
        }
    }

    /**
     * check that we get non-null versions of the <code>IconAndMessageDialog</code> images
     * so we know that the code using them can rely on them.
     *
     * Note that they can be <code>null</code> from SWT.
     *
     */
    public void testGetIconMessageDialogImages() {
        IconAndMessageDialog iconDialog = new MessageDialog(null,
                "testGetDialogIcons", null, "Message", Window.CANCEL,
                new String[] { "cancel" }, 0);

        Image[] images = new Image[] {
                iconDialog.getErrorImage(), iconDialog.getInfoImage(),
                iconDialog.getQuestionImage(), iconDialog.getWarningImage()
            };

        for (int i = 0; i < images.length; i++) {
            assertTrue("Returned null image", images[i] != null);
        }
    }
}
